import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
import { Radio as AntdRadio, Input } from 'antd';
import React, { Fragment } from 'react';
import { useFieldContext } from '../../../contexts/FieldContext';
import createField from '../../../createField';
import useOptions from '../../../hooks/useOptions';
import useOther from '../../../hooks/useSingleOther';
import './index.css';
var _excluded = ['value', 'onChange', 'options', 'itemProps'];
var CheckboxWithOther = function CheckboxWithOther(_ref) {
  var value = _ref.value,
    onChange = _ref.onChange,
    optionsProp = _ref.options,
    itemProps = _ref.itemProps,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useOptions = useOptions(optionsProp),
    options = _useOptions.options;
  var _useFieldContext = useFieldContext(),
    label = _useFieldContext.label;
  var _useOther = useOther({
      value: value,
      onChange: onChange,
      options: options,
    }),
    otherChecked = _useOther.otherChecked,
    changeOtherChecked = _useOther.changeOtherChecked,
    selectedValue = _useOther.selectedValue,
    changeSelectedValue = _useOther.changeSelectedValue,
    otherValue = _useOther.otherValue,
    changeOtherValue = _useOther.changeOtherValue;
  return /*#__PURE__*/ React.createElement(
    Fragment,
    null,
    /*#__PURE__*/ React.createElement(
      AntdRadio.Group,
      _objectSpread(
        _objectSpread(
          {
            value: selectedValue,
            onChange: function onChange(event) {
              changeSelectedValue(event.target.value);
            },
          },
          rest,
        ),
        {},
        {
          style: {
            marginRight: 10,
          },
        },
      ),
      options.map(function (item) {
        return /*#__PURE__*/ React.createElement(
          AntdRadio,
          _objectSpread(
            {
              key: item.value,
              value: item.value,
            },
            typeof itemProps == 'function' ? itemProps(item) : itemProps,
          ),
          item.label,
        );
      }),
    ),
    /*#__PURE__*/ React.createElement(
      AntdRadio,
      {
        checked: otherChecked,
        onChange: function onChange(event) {
          return changeOtherChecked(
            event === null || event === void 0 ? void 0 : event.target.checked,
          );
        },
      },
      '\u5176\u4ED6',
    ),
    otherChecked
      ? /*#__PURE__*/ React.createElement(Input, {
          placeholder: '\u8BF7\u8F93\u5165'.concat(label || ''),
          style: {
            width: 120,
          },
          maxLength: 100,
          value: otherValue,
          onChange: function onChange(event) {
            return changeOtherValue(
              event === null || event === void 0 ? void 0 : event.target.value,
            );
          },
        })
      : null,
  );
};
export default createField(CheckboxWithOther);
